package dontCare.gwtester.client.puzzlers;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import dontCare.gwtester.client.tool.SourceUrl;
import dontCare.gwtester.client.tool.UnitWidget;

public class Album7 extends UnitWidget{
	private static Album7UiBinder uiBinder = GWT.create(Album7UiBinder.class);
	interface Album7UiBinder extends UiBinder<Widget, Album7> {}

	@UiField Label bigProblem;
	@UiField Label whatsInName;
	@UiField Label nameGame;
	@UiField Label modSquad;
	@UiField Label ssss;
	
	public Album7() {
		initWidget(uiBinder.createAndBindUi(this));
		bigProblem();
		whatsInName();
		nameGame();
		modSquad.setText(""+Math.abs(Integer.MIN_VALUE));
		ssss.setText(""+(-2000000000-2000000000));
	}

	private void bigProblem() {
		BigInteger fiveThousand = new BigInteger("5000");
		BigInteger fiftyThousand = new BigInteger("50000");
		BigInteger fiveHundredThousand = new BigInteger("500000");
		BigInteger total = BigInteger.ZERO;
		total.add(fiveThousand);
		total.add(fiftyThousand);
		total.add(fiveHundredThousand);
		bigProblem.setText(total.toString());
	}
	
	private void whatsInName() {
		Set<Name> s = new HashSet<Name>();
		s.add(new Name("Ps", "Monkey"));
		whatsInName.setText(""+s.contains(new Name("Ps", "Monkey")));
	}
	
	private void nameGame(){
		Map<String, String> m = new IdentityHashMap<String, String>();
		m.put("Mickey", "Mouse");
		m.put("Mickey", "Mantle");
		nameGame.setText(""+m.size());
	}

	@Override
	public List<String> getSourceUrl() {
		ArrayList<String> result = new ArrayList<String>();
		result.add(SourceUrl.genJava(Album7.class));
		result.add(SourceUrl.genUiXml(Album7.class));
		return result;
	}

	@Override
	public HTML getDescription() {
		return new HTML("《Java Puzzlers》 Chapter 7 puzzler 集合" +
				"<br/>Puzzler 64～65：僅測試關鍵點 ");
	}

	@Override
	public String getName() {
		return "CH.7 Album";
	}
}

//Puzzler 57
class Name{
	private final String first;
	private final String last;
	
	public Name(String first, String last){
		this.first=first;
		this.last=last;
	}
	
	public boolean equals(Object o){
		if(!(o instanceof Name)){
			return false;
		}
		Name n=(Name) o;
		return n.first.equals(first) && n.last.equals(last);
	}
}
//